home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 123 / cdrom123.iso / essenc / extens / wweb / Web Developer.xpi / chrome / webdeveloper.jar / content / webdeveloper / miscellaneous.js < prev    next >
Encoding:
JavaScript  |  2004-11-21  |  9.0 KB  |  258 lines

  1. // Clears the cache
  2. function webdeveloper_clearCache()
  3. {
  4.     const cacheService = Components.classes["@mozilla.org/network/cache-service;1"].getService(Components.interfaces.nsICacheService);
  5.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  6.  
  7.     cacheService.evictEntries(Components.interfaces.nsICache.STORE_ON_DISK);
  8.     cacheService.evictEntries(Components.interfaces.nsICache.STORE_IN_MEMORY);
  9.  
  10.     alert(stringBundle.getString("webdeveloper_clearCacheResult"));
  11. }
  12.  
  13. // Clears the history
  14. function webdeveloper_clearHistory()
  15. {
  16.     const stringBundle = document.getElementById("webdeveloper-string-bundle");
  17.  
  18.     Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory).removeAllPages();
  19.  
  20.     alert(stringBundle.getString("webdeveloper_clearHistoryResult"));
  21. }
  22.  
  23. // Clears the HTTP authentication
  24. function webdeveloper_clearHTTPAuthentication()
  25. {
  26.     const authenticationManager = Components.classes["@mozilla.org/network/http-auth-manager;1"].getService(Components.interfaces.nsIHttpAuthManager);
  27.     const stringBundle          = document.getElementById("webdeveloper-string-bundle");
  28.  
  29.     authenticationManager.clearAll();
  30.  
  31.     alert(stringBundle.getString("webdeveloper_clearHTTPAuthenticationResult"));
  32. }
  33.  
  34. // Clears all session cookies
  35. function webdeveloper_clearSessionCookies()
  36. {
  37.     const cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
  38.     const cookies       = cookieManager.enumerator;
  39.     const stringBundle  = document.getElementById("webdeveloper-string-bundle");
  40.  
  41.     var removed = 0;
  42.  
  43.     // Loop through the cookies
  44.     while(cookies.hasMoreElements())
  45.     {
  46.         var cookie = cookies.getNext();
  47.  
  48.         // If this is a cookie with no expiration
  49.         if(cookie instanceof Components.interfaces.nsICookie && cookie.expires == "0")
  50.         {
  51.             cookieManager.remove(cookie.host, cookie.name, cookie.path, false);
  52.             removed++;
  53.         }
  54.     }
  55.  
  56.     // If one session cookie was removed
  57.     if(removed == 1)
  58.     {
  59.         alert(stringBundle.getString("webdeveloper_clearSessionCookiesSingleResult"));
  60.     }
  61.     else
  62.     {
  63.         alert(stringBundle.getFormattedString("webdeveloper_clearSessionCookiesMultipleResult", [removed]));
  64.     }
  65. }
  66.  
  67. // Deletes all the cookies for the current domain
  68. function webdeveloper_deleteDomainCookies()
  69. {
  70.     const content       = window.document.getElementById("content");
  71.     const cookieManager = Components.classes["@mozilla.org/cookiemanager;1"].getService(Components.interfaces.nsICookieManager);
  72.     const mainTabBox    = content.mTabBox;
  73.     const documentList  = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  74.     const stringBundle  = document.getElementById("webdeveloper-string-bundle");
  75.  
  76.     var cookie        = null;
  77.     var cookies       = new Array();
  78.     var cookiesLength = null;
  79.     var pageDocument  = null;
  80.  
  81.     // Loop through the documents
  82.     for(var i = 0; i < documentList.length; i++)
  83.     {
  84.         pageDocument = documentList[i];
  85.         cookies      = cookies.concat(webdeveloper_getCookies(pageDocument.location.hostname, false));
  86.     }
  87.  
  88.     cookiesLength = cookies.length;
  89.  
  90.     // Loop through all the cookies
  91.     for(i = 0 ; i < cookiesLength; i++)
  92.     {
  93.         cookie = cookies[i];
  94.  
  95.         cookieManager.remove(cookie.host, cookie.name, cookie.path, false);
  96.     }
  97.  
  98.     // If one cookie was found
  99.     if(cookiesLength == 1)
  100.     {
  101.         alert(stringBundle.getString("webdeveloper_deleteDomainCookiesSingleResult"));
  102.     }
  103.     else
  104.     {
  105.         alert(stringBundle.getFormattedString("webdeveloper_deleteDomainCookiesMultipleResult", [cookiesLength]));
  106.     }
  107. }
  108.  
  109. // Linearizes all elements
  110. function webdeveloper_linearizePage(element, applyStyle)
  111. {
  112.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/linearize_page.css", "webdeveloper-linearize-page", applyStyle);
  113. }
  114.  
  115. // Opens the Java Console
  116. function webdeveloper_openJavaConsole()
  117. {
  118.     Components.classes["@mozilla.org/oji/jvm-mgr;1"].getService(Components.interfaces.nsIJVMManager).showJavaConsole();
  119. }
  120.  
  121. // Toggles comments
  122. function webdeveloper_toggleComments(element, applyStyle)
  123. {
  124.     const content      = window.document.getElementById("content");
  125.     const mainTabBox   = content.mTabBox;
  126.     const documentList = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  127.     const show         = element.getAttribute("checked");
  128.  
  129.     var pageDocument = null;
  130.  
  131.     // Loop through the documents
  132.     for(var i = 0; i < documentList.length; i++)
  133.     {
  134.         pageDocument = documentList[i];
  135.         webdeveloper_toggleCommentsForDocument(pageDocument, show);
  136.     }
  137.  
  138.     webdeveloper_toggleStyleSheet(element, "chrome://webdeveloper/content/stylesheets/show_comments.css", "webdeveloper-show-comments", applyStyle);
  139.     webdeveloper_toggleFeatureTooltipStyles(element, "webdeveloper-show-comments-tooltips", "div.webdeveloper-comment-icon, div.webdeveloper-comment-text, div.webdeveloper-comment-text *");
  140. }
  141.  
  142. // Toggles all links on the page between visited and unvisited
  143. function webdeveloper_toggleVisitedLinks(visited)
  144. {
  145.     const content        = window.document.getElementById("content");
  146.     const globalHistory  = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIGlobalHistory);
  147.     const mainTabBox     = content.mTabBox;
  148.     const documentList   = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  149.  
  150.     var browserHistory = null;
  151.     var href           = null;
  152.     var link           = null;
  153.     var linkList       = null;
  154.     var pageDocument   = null;
  155.  
  156.     // Try to get the new history component
  157.     try
  158.     {
  159.         browserHistory = Components.classes["@mozilla.org/browser/global-history;2"].getService(Components.interfaces.nsIBrowserHistory);
  160.     }
  161.     catch(exception)
  162.     {
  163.         browserHistory = Components.classes["@mozilla.org/browser/global-history;1"].getService(Components.interfaces.nsIBrowserHistory);
  164.     }
  165.  
  166.     // Loop through the documents
  167.     for(var i = 0; i < documentList.length; i++)
  168.     {
  169.         pageDocument = documentList[i];
  170.         linkList     = pageDocument.getElementsByTagName("a");
  171.  
  172.         // Loop through all the links
  173.         for(var j = 0; j < linkList.length; j++)
  174.         {
  175.             link = linkList[j];
  176.             href = link.href;
  177.  
  178.             // If this link has an href
  179.             if(href)
  180.             {
  181.                 // If marking links as visited
  182.                 if(visited && !globalHistory.isVisited(href))
  183.                 {
  184.                     globalHistory.addPage(href);
  185.                 }
  186.                 else if(globalHistory.isVisited(href))
  187.                 {
  188.                     browserHistory.removePage(href);
  189.                 }
  190.  
  191.                 // Force the browser to recheck the history by changing the href
  192.                 link.href = "";
  193.                 link.href = href;
  194.             }
  195.         }
  196.     }
  197. }
  198.  
  199. // Zooms the content
  200. function webdeveloper_zoom(factor)
  201. {
  202.     const content      = window.document.getElementById("content");
  203.     const mainTabBox   = content.mTabBox;
  204.     const documentList = webdeveloper_getDocuments(content.browsers[mainTabBox.selectedIndex].contentWindow, new Array());
  205.  
  206.     var image        = null;
  207.     var imageList    = null;
  208.     var pageDocument = null;
  209.  
  210.     // Loop through the documents
  211.     for(var i = 0; i < documentList.length; i++)
  212.     {
  213.         pageDocument = documentList[i];
  214.         imageList    = pageDocument.getElementsByTagName("img");
  215.  
  216.         webdeveloper_zoomText(pageDocument.documentElement, factor);
  217.  
  218.         // Loop through the images
  219.         for(var j = 0; j < imageList.length; j++)
  220.         {
  221.             image = imageList[j];
  222.  
  223.             image.setAttribute("width", parseInt(image.getAttribute("width") * factor));
  224.             image.setAttribute("height", parseInt(image.getAttribute("height") * factor));
  225.         }
  226.     }
  227. }
  228.  
  229. // Zooms the text
  230. function webdeveloper_zoomText(node, factor)
  231. {
  232.     const childNodeList = node.childNodes;
  233.     const lineHeight    = window.getComputedStyle(node, "").getPropertyValue("line-height");
  234.     const textSize      = window.getComputedStyle(node, "").getPropertyValue("font-size");
  235.  
  236.     var childNode = null;
  237.  
  238.     // Loop through the child nodes
  239.     for(var i = 0; i < childNodeList.length; i++)
  240.     {
  241.         childNode = childNodeList[i];
  242.  
  243.         // If this is an element
  244.         if(childNode.nodeType == 1)
  245.         {
  246.             webdeveloper_zoomText(childNode, factor);
  247.         }
  248.     }
  249.  
  250.     node.style.fontSize = parseInt(textSize.substr(0, textSize.length - 2) * factor) + "px";
  251.  
  252.     // If the line height is not normal
  253.     if(lineHeight != "normal")
  254.     {
  255.         node.style.lineHeight = parseInt(lineHeight.substr(0, lineHeight.length - 2) * factor) + "px";
  256.     }
  257. }
  258.